mui.init({
    beforeback: function () {
        //获得列表界面的webview
        var mem = plus.webview.getWebviewById("src/templates/tab/member.html");
        var boughtObj = plus.webview.getWebviewById("src/templates/tab/bought.html");
        //触发列表界面的自定义事件（dataList）,从而进行数据刷新
        mui.fire(mem, 'dataList');
        mui.fire(boughtObj, 'updateData');
        //返回true，继续页面关闭逻辑
        return true;
    }
});

var setData;
mui.plusReady(function () {
    setData = new Vue({
        el: '#SETbox',
        data: {
            loginSta: 0,
            version: '0.0',
        },
        mounted() {
            var self = this;
            self.updateStatus();
            plus.runtime.getProperty(plus.runtime.appid, function (inf) {
                self.version = inf.version;
            });
        },
        methods: {
            updateStatus:function(){
                var api_host = plus.storage.getItem('HOST_URL');
                var self = this;
                mui.ajax({
                    url: api_host + '/api/linxuan/user/checkLoginStatus',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            self.loginSta = 1;
                        } else {
                            self.loginSta = 0;
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('登录状态请求失败请重试', {duration: '300'});
                    }
                });
            },
            reset_ones: function () {
                mui.confirm('您确定要退出登录吗？', '', function (e) {
                    if (e.index == 1) {
                        var api_host = plus.storage.getItem('HOST_URL');
                        var self = this;
                        mui.ajax({
                            url: api_host + '/api/linxuan/user/exitLogin',
                            dataType: 'json',
                            headers:{'User-Token':plus.storage.getItem('UserToken')},
                            timeout:3000,
                            type: 'get',
                            success: function (msg) {
                                mui.toast(msg.msg, {duration: '300'});
                                plus.storage.setItem('UserToken',msg.data.userToken);
                                setTimeout(function () {
                                    mui.back();
                                }, 1500)
                            },
                            error: function (xhr, type, errorThrown) {
                                mui.toast('登录状态请求失败请重试', {duration: '300'});
                            }
                        });
                    } else {
                        mui.toast('取消退出!', {
                            duration: '1000',
                            type: 'div'
                        });
                    }
                })
            },
            feedback: function () {
                mui.openWindow({
                    url: 'feedback.html',
                    createNew:false,
                    show:{
                        autoShow:true,
                        anishow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            help: function () {
                mui.openWindow({
                    url: 'help.html',
                    createNew:false,
                    show:{
                        autoShow:true,
                        anishow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            aboutUs: function () {
                mui.openWindow({
                    url: 'aboutUs.html',
                    createNew:false,
                    show:{
                        autoShow:true,
                        anishow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            clearCache: function () {
                if(mui.os.ios){
                    mui.toast("正在清理中...", {duration: '2000',type:'div'});
                    mui.later(function () {
                        mui.toast("缓存清理完毕!", {duration: '800',type:'div'});
                    },2000);
                }else if(mui.os.android){
                    plus.cache.calculate(function(size) {
                        console.log(size)
                        sizeCache = size;
                        var size_m = parseFloat(sizeCache / (1024 * 1024)).toFixed(2);
                        if(size_m > 1) {
                            mui.confirm("您目前的系统缓存为" +size_m + "M？", "清除缓存", ["确认", "取消"], function(e) {
                                if(e.index == 1) {} else {
                                    plus.cache.clear(function() {
                                        mui.toast("缓存清除完毕");
                                    });
                                }
                            });
                        }else{
                            mui.toast("没有缓存");
                        }
                    });
                }
            },
            updateVersion: function () {
                ApplicationUpdateTool('../tab/update.html');
            },
        }
    })
})
